  <?php
  //$path="C:/xampp/htdocs/00_JO/JOii/";
  	include ("../JO_01_configuration.php");
  	$JO_MySQL = new mysqli( $JO_DB_host, $JO_DB_user, $JO_DB_password, $JO_DB_database,false, 65536 );
	$JO_MySQL -> query( "SET NAMES 'UTF8'" );
	 include_once('../JO_02_function.php');
  		$sea=$_GET['SO_sea'];
		$sea2=$_GET['SO_sea2'];
		$sea3=$_GET['SO_sea3'];
		$sea4=$_GET['SO_sea4'];
  ?>
	<?php if($sea4=='INCOM'){ ?>
       <table class="tbi2" width ="100%" style="">
          <tr style="">
            <th >Mã Lệnh 			</th >
            <th >Đơn Vị Cung Cấp 	</th >
           	<th>BEELINE</th>
            <th >VINAPHONE				</th >
            <th >SFONE				</th >
            <th >MOBIPHONE 				</td >
            <th >CITYFONE			</th >
            <th >VIETTEL			</th >
            <th >TỔNG CỘNG		    </th >
          </tr>
          <tr>
            <td >NE</td>
            <td >NEOWIZ_HT</td>
            
            <?php 
			$s_SQLCommand = "call JO_14_count('NE','$sea','$sea2','$sea3','$sea4');";
            $resultNE=JO_query($s_SQLCommand);
			
			 if($resultNE->num_rows)
			 $resultNEs=$resultNE->fetch_array();
			 ?>
            <td><?=isset($resultNEs['BEE'])?$resultNEs['BEE']:""?></td>
           	<td><?=isset($resultNEs['VINAPHONE'])?$resultNEs['VINAPHONE']:""?></td>
            <td><?=isset($resultNEs['SFONE'])?$resultNEs['SFONE']:""?>		  </td>
            <td><?=isset($resultNEs['MOBI'])?$resultNEs['MOBI']:""?>		  </td>
            <td><?=isset($resultNEs['VIETNAM'])?$resultNEs['VIETNAM']:""?>	  </td>
            <td><?=isset($resultNEs['VIETTEL'])?$resultNEs['VIETTEL']:""?>	  </td>
            <td><?=isset($resultNEs['dem'])?$resultNEs['dem']:""?>			  </td>
          </tr>
        </table>
      <?php } else{ ?>
	    <table class="tbi2" width ="100%" style="">
        
          <tr style="">
            <th >Mã Lệnh 			</th >
            <th >Đơn Vị Cung Cấp 	</th >
            <th>BEELINE</th>
            <th >VINAPHONE				</th >
            <th >SFONE				</th >
            <th >MOBIPHONE 				</th >
            <th >VIETNAMMOBILE			</th >
            <th >VIETTEL			</th >
            <th >TỔNG CỘNG 			</th >
          </tr>
           <tr>
            <td >HT						  </td>
            <td >NEOWIZ_HT				  </td>
           
           <?php 
            $HQSQLCommands = 	"SELECT DISTINCT cmdcode,
			(SELECT COUNT(*) FROM sms WHERE opid='BEE8x88' AND cmdcode='HT' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime ) AS BEE,
		(SELECT COUNT(*) FROM sms WHERE opid='VTL8x88' AND cmdcode='HT' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime ) AS VIETTEL,
		(SELECT COUNT(*) FROM sms WHERE opid='VMS8x88' AND cmdcode='HT' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime ) AS MOBI,
		(SELECT COUNT(*) FROM sms WHERE opid='GPC8x88' AND cmdcode='HT' AND (sms.requesttime BETWEEN '$sea' AND $sea2) AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime ) AS VINAPHONE,
		(SELECT COUNT(*) FROM sms WHERE opid='VNM8x88' AND cmdcode='HT' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime) AS VIETNAM,
		(SELECT COUNT(*) FROM sms WHERE opid='SFN8x88' AND cmdcode='HT' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%' ORDER BY sms.requesttime) AS SFONE ,
		 (SELECT COUNT(*) FROM sms WHERE cmdcode ='HT' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%' AND sms.opid NOT IN ('BEE8x88','EVN8x88')  ORDER BY sms.requesttime) as dem
	FROM sms WHERE cmdcode ='HT';";
	
            $resultHQ=JO_query($HQSQLCommands);
			if ($resultHQ === FALSE) { 
			echo 'lỗi2';
			//die(mysqli_error()); 
			}
			if($resultHQ->num_rows)
			while( $resultHQs=$resultHQ->fetch_array()){
   		   ?>
           <td><?=isset($resultHQs['BEE'])?$resultHQs['BEE']:""?></td>
           	<td><?=isset($resultHQs['VINAPHONE'])?$resultHQs['VINAPHONE']:""?></td>
            <td><?=isset($resultHQs['SFONE'])?$resultHQs['SFONE']:""?>        </td>
            <td><?=isset($resultHQs['MOBI'])?$resultHQs['MOBI']:""?>		  </td>
            <td><?=isset($resultHQs['VIETNAM'])?$resultHQs['VIETNAM']:""?>	  </td>
            <td><?=isset($resultHQs['VIETTEL'])?$resultHQs['VIETTEL']:""?>	  </td>
            <td><?=isset($resultHQs['dem'])?$resultHQs['dem']:""?>			  </td>
			<?php  }?>
          </tr>
          <tr>
            <td >HQ						  </td>
            <td >NEOWIZ_HT				  </td>
            
           <?php 
            $HQSQLCommands = 	"SELECT DISTINCT cmdcode,
			(SELECT COUNT(*) FROM sms WHERE opid='BEE8x88' AND cmdcode='HQ' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime ) AS BEE,
		(SELECT COUNT(*) FROM sms WHERE opid='VTL8x88' AND cmdcode='HQ' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime ) AS VIETTEL,
		(SELECT COUNT(*) FROM sms WHERE opid='VMS8x88' AND cmdcode='HQ' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime ) AS MOBI,
		(SELECT COUNT(*) FROM sms WHERE opid='GPC8x88' AND cmdcode='HQ' AND (sms.requesttime BETWEEN '$sea' AND $sea2) AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime ) AS VINAPHONE,
		(SELECT COUNT(*) FROM sms WHERE opid='VNM8x88' AND cmdcode='HQ' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime) AS VIETNAM,
		(SELECT COUNT(*) FROM sms WHERE opid='SFN8x88' AND cmdcode='HQ' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%' ORDER BY sms.requesttime) AS SFONE ,
		 (SELECT COUNT(*) FROM sms WHERE cmdcode ='HQ' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%' AND sms.opid NOT IN ('BEE8x88','EVN8x88')  ORDER BY sms.requesttime) as dem
	FROM sms WHERE cmdcode ='HQ';";
	
            $resultHQ=JO_query($HQSQLCommands);
			if ($resultHQ === FALSE) { 
			echo 'lỗi2';
			//die(mysqli_error()); 
			}
			if($resultHQ->num_rows)
			while( $resultHQs=$resultHQ->fetch_array()){
   		   ?>
           <td><?=isset($resultHQs['BEE'])?$resultHQs['BEE']:""?></td>
           	<td><?=isset($resultHQs['VINAPHONE'])?$resultHQs['VINAPHONE']:""?></td>
            <td><?=isset($resultHQs['SFONE'])?$resultHQs['SFONE']:""?>        </td>
            <td><?=isset($resultHQs['MOBI'])?$resultHQs['MOBI']:""?>		  </td>
            <td><?=isset($resultHQs['VIETNAM'])?$resultHQs['VIETNAM']:""?>	  </td>
            <td><?=isset($resultHQs['VIETTEL'])?$resultHQs['VIETTEL']:""?>	  </td>
            <td><?=isset($resultHQs['dem'])?$resultHQs['dem']:""?>			  </td>
			<?php  }?>
          </tr>
           <tr>
            <td >NP					  </td>
            <td >NEOWIZ_HT			  </td>
            
             <?php 
			 global $JO_MySQL;
			 $NPSQLCommand = "SELECT DISTINCT cmdcode,
			 (SELECT COUNT(*) FROM sms WHERE opid='BEE8x88' AND cmdcode='NP' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime ) AS BEE,
		(SELECT COUNT(*) FROM sms WHERE opid='VTL8x88' AND cmdcode='NP' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime ) AS VIETTEL,
		(SELECT COUNT(*) FROM sms WHERE opid='VMS8x88' AND cmdcode='NP' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'   ORDER BY sms.requesttime ) AS MOBI,
		(SELECT COUNT(*) FROM sms WHERE opid='GPC8x88' AND cmdcode='NP' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime ) AS VINAPHONE,
		(SELECT COUNT(*) FROM sms WHERE opid='VNM8x88' AND cmdcode='NP' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%'  ORDER BY sms.requesttime) AS VIETNAM,
		(SELECT COUNT(*) FROM sms WHERE opid='SFN8x88' AND cmdcode='NP' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%' ORDER BY sms.requesttime) AS SFONE ,
		 (SELECT COUNT(*) FROM sms WHERE cmdcode ='NP' AND (sms.requesttime BETWEEN '$sea' AND '$sea2') AND sms.src LIKE '%$sea3%' AND sms.opid NOT IN ('BEE8x88','EVN8x88')  ORDER BY sms.requesttime) as dem
	FROM sms WHERE cmdcode ='NP';";
	
			  $resultNP=JO_query($NPSQLCommand);
			 //if($resultNP->num_rows)
			  $resultNPs=$resultNP->fetch_array()
			 ?>
             <td><?=isset($resultNPs['BEE'])?$resultNPs['BEE']:""?></td>
            <td><?=isset($resultNPs['VINAPHONE'])?$resultNPs['VINAPHONE']:""?></td>
            <td><?=isset($resultNPs['SFONE'])?$resultNPs['SFONE']:""?>		  </td>
            <td><?=isset($resultNPs['MOBI'])?$resultNPs['MOBI']:""?>		  </td>
            <td><?=isset($resultNPs['VIETNAM'])?$resultNPs['VIETNAM']:""?>	  </td>
            <td><?=isset($resultNPs['VIETTEL'])?$resultNPs['VIETTEL']:""?> 	  </td>
            <td><?=isset($resultNPs['dem'])?$resultNPs['dem']:""?>			  </td>
          </tr>
        </table>
	  <?php } $JO_MySQL -> close( );?>